<?php
include_once BXD_INCLUDEPATH . 'core/Response.php';

/**
 * Classe che viene estesa in tutti i controller per dare loro le funzionalità
 * di base come la gestione della RESPONSE dei LAYOUT e delle VIEW
 *
 * @author Damiano Ciarla
 * @category Core
 * @version 1.0
 */

class Controller
{
	protected $layout	= NULL;
	protected $response	= NULL;

	function  __construct()
	{
		global $response;
		
		$this->response = (($response === NULL) ? new Response() : $response);
	}

	public function getResponse()
	{
		return $this->response;
	}

	public function setLayout($layout)
	{
		$this->layout = $layout;
	}

	public function getLayout()
	{
		return $this->layout;
	}

	public function addContent($content, $placemark='content')
	{
		BXD::getInstance()->addContent($content, $placemark);
	}

	public function replaceContent($content, $placemark='content')
	{
		BXD::getInstance()->replaceContent($content, $placemark);
	}

	public function getContent($content)
	{
		$file = BXD_INCLUDEPATH_SITE . BXDConfig::$VIEW_FOLDER . '/' . $content . '.page.php';

		if(file_exists($file))
		{
			$response = $this->response;

			ob_start();

			include_once $file;

			$out = ob_get_contents();

			ob_end_clean();

			return $out;
		}
		else return false;
	}
}
?>
